<?php
	
class Default_Model_Yatzy_Result
{
	protected $date = null;
	protected $ones = null;
	protected $twos = null;
	protected $threes = null;
	protected $fours = null;
	protected $fives = null;
	protected $sixes = null;
	protected $subSum = null;
	protected $bonus = null;
	protected $pair = null;
	protected $twoPair = null;
	protected $threeOfAKind = null;
	protected $fourOfAKind = null;
	protected $smallStright = null;
	protected $bigStright = null;
	protected $fullHouse = null;
	protected $chance = null;
	protected $yatzy = null;
	protected $sum = null;
	protected $completeRounds = null;
    protected $_mapper;
    protected $_id;
	protected $userId;
	protected $_finnished;
	protected $completeDiceThrows;
	protected $dice;
		
	public function __construct(array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value)
    {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        $this->$method($value);
    }

    public function __get($name)
    {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        return $this->$method();
    }

    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }
	
	public function getDate(){return $this->date;}
	public function setDate($date){$this->date = $date;return $this;}
	public function getOnes(){return $this->ones;}
	public function setOnes($ones){$this->ones = $ones;return $this;}
	public function getTwos(){return $this->twos;}
	public function setTwos($twos){$this->twos = $twos;return $this;}
	public function getThrees(){return $this->threes;}
	public function setThrees($threes){$this->threes = $threes;return $this;}
	public function getFours(){return $this->fours;}
	public function setFours($fours){$this->fours = $fours;return $this;}
	public function getFives(){return $this->fives;}
	public function setFives($fives){$this->fives = $fives;return $this;}
	public function getSixes(){return $this->sixes;}
	public function setSixes($sixes){$this->sixes = $sixes;return $this;}
	
	public function getSubSum()
	{
		return $this->ones + $this->twos + $this->threes + $this->fours + $this->fives + $this->sixes;
	}
	
	public function setSubSum($subSum)
	{
		$this->subSum = $subSum;
		return $this;
	}
	
	public function getBonus()
	{
		$bonus = 0;
		if($this->getSubSum() >= 63)
		{
			$bonus = 50;
		}		
		return $bonus;
	}
	
	public function setBonus($bonus)
	{
		$this->bonus = $bonus;
		return $this;
	}
	
	public function getPair(){return $this->pair;}
	public function setPair($pair){$this->pair = $pair;return $this;}
	public function getTwoPair(){return $this->twoPair;}
	public function setTwoPair($twopair){$this->twoPair = $twopair;return $this;}
	public function getThreeOfAKind(){return $this->threeOfAKind;}
	public function setThreeOfAKind($threeofakind){$this->threeOfAKind = $threeofakind;return $this;}
	public function getFourOfAKind(){return $this->fourOfAKind;}
	public function setFourOfAKind($fourOfAKind){$this->fourOfAKind = $fourOfAKind;return $this;}
	public function getSmallStraight(){return $this->smallStright;}
	public function setSmallStraight($smallStright){$this->smallStright = $smallStright;return $this;}
	public function getBigStraight(){return $this->bigStright;}
	public function setBigStraight($bigStright){$this->bigStright = $bigStright;return $this;}
	public function getFullHouse(){return $this->fullHouse;}
	public function setFullHouse($fullHouse){$this->fullHouse = $fullHouse;return $this;}
	public function getChance(){return $this->chance;}
	public function setChance($chance){$this->chance = $chance;return $this;}
	public function getYatzy(){return $this->yatzy;}
	public function setYatzy($yatzy){$this->yatzy = $yatzy;return $this;}
	public function getSum(){return $this->sum + $this->getBonus();}
	public function setSum($sum){$this->sum = $sum; return $this;}
	public function addSum($value){$this->sum += $value;return $this;}

	public function getCompleteRounds(){return $this->completeRounds;}
	public function setCompleteRounds($completeRounds){$this->completeRounds = $completeRounds;return $this;}
	public function addCompleteRound(){++$this->completeRounds;return $this;}

	public function getCompleteDiceThrows(){return $this->completeDiceThrows;}
	public function setCompleteDiceThrows($completeDiceThrows){$this->completeDiceThrows = $completeDiceThrows;return $this;}
	public function addCompleteDiceThrows(){++$this->completeDiceThrows;return $this;}

	public function setDice($dice){$this->dice = $dice; return $this;}
	public function getDice(){return $this->dice;}
	
	public function getUserId(){return $this->userId;}
	public function setUserId($userId){$this->userId = $userId;return $this;}
	public function getFinnished(){return $this->_finnished;}
	public function setFinnished($finnished){$this->_finnished = $finnished;return $this;}
	
	public function setId($id)
    {
        $this->_id = (int) $id;
        return $this;
    }

    public function getId()
    {
        return $this->_id;
    }

    public function setMapper($mapper)
    {
        $this->_mapper = $mapper;
        return $this;
    }

    public function getMapper()
    {
        if (null === $this->_mapper) {
            $this->setMapper(new Default_Model_Yatzy_ResultMapper());
        }
        return $this->_mapper;
    }

    public function save()
    {
        return $this->getMapper()->save($this);
    }
	
	public function getTopTen()
	{
		return $this->getMapper()->getTopTen($this);
	}
	
	public function hasUnfinnishedGame($userId)
	{
		return $this->getMapper()->hasUnfinnishedGame($userId);		
	}
	
	public function getUnfinnishedGame($userId)
	{
		return $this->getMapper()->getUnfinnishedGame($userId);				
	}
	
}

?>